package com.zlzxm.shoesmarket.viewmodel;

import android.text.TextUtils;

import androidx.lifecycle.MutableLiveData;

import com.zlzxm.shoesmarket.net.BaseCallBack;
import com.zlzxm.shoesmarket.net.repository.NoteRepository;
import com.zlzxm.shoesmarket.net.request.RqNoteAdd;
import com.zlzxm.shoesmarket.net.respone.RpNoteList;
import com.zlzxm.shoesmarket.util.RxAndroidHelp;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * CREATE BY zlzxm ON 2021/5/19
 */
public class VMAddNote extends BaseViewModel {

    private NoteRepository noteRepository = new NoteRepository();

    public  MutableLiveData<String> liveSelectType = new MutableLiveData<>();
    public  MutableLiveData<String> liveType = new MutableLiveData<>();

    public void add(String money){

        if(liveSelectType.getValue()==null){

            liveErrorToast.setValue("请选择分类");
            return;
        }
        if(TextUtils.isEmpty(money)){

            liveErrorToast.setValue("请输入金额");

            return;
        }

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

        String data = simpleDateFormat.format(new Date());

        RqNoteAdd rqNoteAdd = new RqNoteAdd(data,
                liveType.getValue(),money,liveSelectType.getValue(),"");

        noteRepository.add(rqNoteAdd)
                .compose(RxAndroidHelp.turn())
                .subscribe(new BaseCallBack<String>() {
                    @Override
                    protected void succeed(String msg, String s) {

                        liveSucceedToast.setValue(msg);

                    }

                    @Override
                    protected void failed(String msg) {

                        liveErrorToast.setValue(msg);
                    }

                    @Override
                    protected void notLogin() {

                    }
                },throwableCallback);



    }



}
